// 
//  Security.h
//  LoginSecurity
//  
//  Created by Ryan Latta on 2008-12-03.
//  Copyright 2008 Ryan Latta. All rights reserved.
// 
#ifndef SECURITY_H_QA7PKJ0W
#define SECURITY_H_QA7PKJ0W

#include <fstream>
#include <cstdlib>
#include <string>
#include <sstream>
#include "RandomNumbers.h"
using namespace std;

#endif /* end of include guard: SECURITY_H_QA7PKJ0W */


//#ifdef __cplusplus
//extern "C" {
//#endif

/**
 * This class represents the base class for the Template method.  It serves as an interface
 * to create specific questions using various algorithms.
 *
 * Derived classes must override generateQuestion() and generateAnswer().  They should also
 * take care to set answer and question for use by the Question class's associate.
 */
class Question
{
public:
  Question ();
  virtual ~Question ();  

  /**
   * makeQuestion is the fuction you call to make whatever concrete question you want, instantiate.
   * It simply calls generateQuestion() and generateAnswer().  This effectively makes your concrete
   * question exist.
  **/
  void makeQuestion () {generateQuestion(); generateAnswer();};
  string getQuestion() {return question;}
  string getAnswer() {return answer;}

  /**
   * This function must be overridden in concrete classes.  It will do the job of generating the
   * question string and setting the member question.  This function is called by makeQuestion()
   * and the result can be grabbed from getQuestion().
   *
   * Note: certain question types will wind up actually doing the work of generateAnswer() here as
   * well.  Sometimes it just works out that way.
  **/
  virtual void generateQuestion() = 0;
  /**
   * This function must also be overridden.  It simply sets the answer member to the correct
   * answer to the question.  The result of this should be grabbed from getAnswer().
   * generateAnswer() is also called by makeQuestion().  
  **/
  virtual void generateAnswer() = 0;

protected:
  string question;
  string answer;
  RandomNumbers *random;
};

/**
 * The goal of this class is to implement various algorithms to choose what kind of concrete
 * questions to ask the user at run time.
 *
 * Ideally this is the starting point for more elaborate selection schemes, but for now it
 * just uses a random number and a switch statement.
**/
class QuestionFactory
{
public:
  QuestionFactory ();
  Question *getQuestion() {return question;}
  virtual ~QuestionFactory ();

private:
  Question *question;
};
/**
 *  This class will generate basic arithmatic for someone to solve.  The constructor will
 *  take two arguments, int low, and int high.  Low and high represent the floor and ceiling of
 *  random numbers to use in arithmetic generation.
 */
class MathQuestion:public Question
{
public:
  MathQuestion (int low = 0, int high = 10);  /**< integers are high and low for random numbers.*/
  virtual ~MathQuestion ();
  void generateQuestion ();
  void generateAnswer();

private:
  float fNumber1;
  float fNumber2;
  int h, l;
  int randomOperation;
  static char operations[];
  ostringstream s;
};
/**
  This class creates simple word questions.  It will read words from a file and then insert spaces
  and various other characters that will make still be easily readable to humans.
*/
class TextQuestion:public Question
{
public:
  TextQuestion ();
  ~TextQuestion ();
  void generateQuestion();
  void generateAnswer();

private:
  bool openFile();
  bool closeFile();
  string getFileChunk();
  string insertSpaces();
  const char getRandomJunk();
  bool isFileOpen();
  ifstream file;
};

//#ifdef __cplusplus
//}
//#endif


